import javax.swing.event.EventListenerList;


public class Service {
	private final EventListenerList serviceListeners = new EventListenerList();

	private static NullService _nullReaction;
	private String _title;

	private String description;
	private boolean isHolded;

	public Service(String title, String description) {
		this.setDescription(description);
		setTitle(title);
	}

	public static Service getNullService() {
		return _nullReaction != null? _nullReaction: (_nullReaction = new NullService());
	}

	private void setTitle(String _title) {
		this._title = _title;
	}

	public String getTitle() {
		return _title;
	}


	public void addListener(ServiceEventListener listener){
		serviceListeners.add(ServiceEventListener.class, listener);
	}

	public void removeListener(ServiceEventListener listener){
		serviceListeners.remove(ServiceEventListener.class, listener);
	}
	
	private ServiceEventListener[] getServiceEventListeners() {
		return serviceListeners.getListeners(ServiceEventListener.class);
	}
	
	public void select() {
		for (ServiceEventListener listener : getServiceEventListeners())
			listener.serviceSelected(this);
	}

	public void unselect() {
		for (ServiceEventListener listener : getServiceEventListeners())
			listener.serviceUnselected(this);
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getDescription() {
		return description;
	}

	public void released() {
		if(!isHolded)
			return;
		isHolded = false;
		for (ServiceEventListener listener : getServiceEventListeners())
			listener.serviceReleased(this);
	}

	public void dragged(int x, int y) {
		for (ServiceEventListener listener : getServiceEventListeners())
			listener.serviceDragged(this, x, y);
	}

	public void holded() {
		if(isHolded)
			return;
		isHolded = true;
	}
}
